package com.yunjian.core.basic.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yunjian.core.basic.mapper.SDataDicMapper;
import com.yunjian.core.basic.model.SDataDic;
import com.yunjian.core.basic.model.SDataDicExample;
import com.yunjian.core.basic.model.SDataDicKey;
import com.yunjian.core.basic.service.CacheService;
import com.yunjian.core.basic.service.SDataDicService;
import com.yunjian.core.basic.vo.CacheType;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class SDataDicServiceImpl implements SDataDicService{
	
	@Autowired
	private CacheService cacheService;
	
	@Autowired
	private SDataDicMapper mapper;

	@Override
	public int countByExample(SDataDicExample example) {
		return mapper.countByExample(example);
	}

	@Override
	public int deleteByExample(SDataDicExample example) {
		return mapper.deleteByExample(example);
	}

	@Override
	public int deleteByPrimaryKey(SDataDicKey key) {
		return mapper.deleteByPrimaryKey(key);
	}

	@Override
	public int insert(SDataDic record) {
		return mapper.insert(record);
	}

	@Override
	public int insertSelective(SDataDic record) {
		return mapper.insertSelective(record);
	}

	@Override
	public List<SDataDic> selectByExample(SDataDicExample example) {
		return mapper.selectByExample(example);
	}

	@Override
	public SDataDic selectByPrimaryKey(SDataDicKey key) {
		return mapper.selectByPrimaryKey(key);
	}

	@Override
	public int updateByExampleSelective(SDataDic record, SDataDicExample example) {
		return mapper.updateByExampleSelective(record, example);
	}

	@Override
	public int updateByExample(SDataDic record, SDataDicExample example) {
		return mapper.updateByExample(record, example);
	}

	@Override
	public int updateByPrimaryKeySelective(SDataDic record) {
		return mapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(SDataDic record) {
		return mapper.updateByPrimaryKey(record);
	}

	@Override
	public SDataDic selectCacheByPrimaryKey(SDataDicKey key) {
		Object cache = cacheService.getCache(CacheType.DATADIC.getCode(), key.getDicGroup() + key.getDicKey());
		if (cache != null) {
			return (SDataDic)cache;
		}
		cache = mapper.selectByPrimaryKey(key);
		cacheService.addCache(CacheType.DATADIC.getCode(), key.getDicGroup() + key.getDicKey(), cache);
		return (SDataDic)cache;
	}

	@Override
	public PageInfo<SDataDic> selectPagedByExample(int page, int rows,
			SDataDicExample example) {
		PageHelper.startPage(page, rows);
		PageInfo<SDataDic> pageInfo = new PageInfo<>(mapper.selectByExample(example));
		return pageInfo;
	}


	
}
